package baiqitun.netfiles.controller;

import baiqitun.netfiles.entity.SysDirectory;
import baiqitun.netfiles.service.SysDirectoryService;
import baiqitun.netfiles.util.ThymeleafUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * 首页
 * @author kedaji
 */
@Controller
public class IndexController {
    @Autowired
    private SysDirectoryService sysDirectoryService;

    @GetMapping("/index")
    public ModelAndView indexPage(){
       return getIndexPageModelAndView();
    }

    @GetMapping("/")
    public ModelAndView welcomePage(){
        return getIndexPageModelAndView();
    }

    @GetMapping("")
    public ModelAndView defaultPage(){
        return getIndexPageModelAndView();
    }

    private ModelAndView getIndexPageModelAndView(){
        ModelAndView mav = ThymeleafUtil.createDefaultModelAndView();
        mav.addObject("title", "远程文件浏览器-首页");
        mav.addObject("roots", sysDirectoryService.listRoot());

        mav.setViewName("index");
        return mav;
    }
}
